package services

import (
	"football/src/models"
	"football/src/utils"
	"strconv"

	"github.com/gin-gonic/gin"
)

func GetFixtures(c *gin.Context) {
	time := c.Query("time")
	page, _ := strconv.Atoi(c.Query("page"))
	limit, _ := strconv.Atoi(c.Query("limit"))
	list, total, err := models.GetFixturesList(page, limit, time)
	if err != nil {
		utils.Error("获取数据失败", err)
		utils.RespFail(c.Writer, "获取数据失败")
		return
	}
	utils.RespOkList(c.Writer, &list, total)
}

func GetOnlineStrategy(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	limit, _ := strconv.Atoi(c.Query("limit"))
	list, total, err := models.GetOnlineStrategyList(page, limit)
	if err != nil {
		utils.Error("获取数据失败", err)
		utils.RespFail(c.Writer, "获取数据失败")
		return
	}
	utils.RespOkList(c.Writer, list, total)
}

func GetStrategyMonitor(c *gin.Context) {

	list, err := models.GetStrategyMonitor(utils.CalculateData)
	if err != nil {
		utils.RespFail(c.Writer, "获取数据失败")
		utils.Error("GetStrategyMonitor failed ", err)
		return
	}
	utils.RespOkList(c.Writer, list, len(list))
}

func GetLeagueList(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	limit, _ := strconv.Atoi(c.Query("limit"))
	list, total, err := models.GetLeagueList(page, limit)
	if err != nil {
		utils.Error("获取数据失败", err)
		utils.RespFail(c.Writer, "获取数据失败")
		return
	}
	utils.RespOkList(c.Writer, &list, total)
}
